<?php namespace Home\Controller;


use Hdphp\Controller\Controller;

class ContentController extends  Controller{
	
	
	public function index(){
		$gid = Q('get.gid',0,'intval');
		$goodsModel = new \Common\Model\Goods;
		$goodsData = $goodsModel->where("gid=$gid")->find();
		$bid = $goodsData['brand_bid'];
		$goodsCid = $goodsData['category_cid'];
		$cateModel  = new \Common\Model\Cate;
		$goodsCateData = $cateModel->where("cid=$goodsCid")->find();
		View::with('goodsCateData',$goodsCateData);
		$goodsCatePid = $goodsCateData['pid'];
		$goodsCateFname = $cateModel->where("cid=$goodsCatePid")->find();
		View::with('goodsCateFname',$goodsCateFname);
		$goodsData['brand_name'] = Db::table('brand')->where("bid={$bid}")->pluck('bname');
		$goodsData['brand_logo'] = Db::table('brand')->where("bid={$bid}")->pluck('logo');
		$goodsData['detail'] = Db::table('goods_detail')->where("goods_gid=$gid")->get();
		View::with('goodsData',$goodsData);
		$goodsAttrData = Db::table('goods_attr')
						->join("type_attribute",'type_attribute_taid','=','taid')
						->where("goods_gid=$gid AND atype=0")
						->get();
		View::with('goodsAttrData',$goodsAttrData);
		$albumData = explode('|', $goodsData['detail'][0]['album']);
		View::with('albumData',$albumData);
		$goodsAttrModel = new \Common\Model\GoodsAttr;
		$specData = $goodsAttrModel
					->join("type_attribute",'type_attribute_taid','=','taid')
					->where("goods_gid=$gid AND atype=1")
					->groupBy("taid")
					->get();
		foreach ($specData as $k => $v) {
			$specData[$k]['son'] = Db::table('goods_attr')
									->where("goods_gid={$gid} AND type_attribute_taid={$v['taid']}")
									->get();
			
		}
		
		
		View::with('specData',$specData);
		View::make();
	}
	//检查
	public function checkinv(){
		$goodsData = array();
		$combine = implode(',', Q('post.combine'));
		$goodsData['add_price'] = Db::table('goods_attr')->where("gaid in (".$combine.")")->sum("add_price");
		$inv = Db::table('goods_list')->where("combine='$combine'")->pluck('inventory');
		$goodsData ['inv'] = $inv;
		$this->ajax($goodsData);
		
	}
} 

 ?>